/*
 * @Descripttion: 
 * @Author: junhuafly
 * @Date: 2020-02-27 11:09:59
 * @LastEditors: junhuafly
 * @Email: junhuafly@163.com
 * @LastEditTime: 2020-04-21 14:53:19
 */
Component({
	data: {
		active: 0,
		list: [{
				"text": "首页",
				icon: 'home-o',
				selectIcon: 'wap-home',
				"iconPath": "/pages/images/icon/common_tab_home_n.png",
				"selectedIconPath": "/pages/images/icon/common_tab_home_s.png",
				"url": '/pages/note/index'
			},
			{
				"text": "商城",
				icon: 'shop-o',
				selectIcon: 'shop',
				"iconPath": "/pages/images/icon/common_tab_store_n.png",
				"selectedIconPath": "/pages/images/icon/common_tab_store_s.png",
				"url": '/pages/mall/index'
			},
			{
				"url": "/pages/post/index",
				"text": "",
				icon: 'add-o',
				selectedIcon: 'add',
				"iconPath": "/pages/images/icon/common_tab_fabu_n.png",
				"selectedIconPath": "/pages/images/icon/common_tab_fabu_n.png",
				isSpecial: true
			},
			{
				"url": "/pages/cart/index",
				icon: 'cart-o',
				selectedIcon: 'cart',
				"text": "购物车",
				"iconPath": "/pages/images/icon/common_tab_shopping cart_n.png",
				"selectedIconPath": "/pages/images/icon/common_tab_shopping cart_s.png"
			},
			{
				"url": "/pages/mine/index",
				icon: 'manager-o',
				selected: 'manager',
				"text": "我的",
				"iconPath": "/pages/images/icon/common_tab_me_n.png",
				"selectedIconPath": "/pages/images/icon/common_tab_me_s.png"
			}
		],
		//适配IphoneX的屏幕底部横线
		isIphoneX: false //app.globalData.isIphoneX
	},

	methods: {
		onChange(event) {
			const url = this.data.list[event.detail].url
			this.setData({
				active: event.detail
			});
			if (this.data.list[event.detail].isSpecial) {
				wx.navigateTo({
					url
				})
			} else {
				wx.switchTab({
					url
				});
			}
		},
		switchTab(e) {
			const dataset = e.currentTarget.dataset
			const path = dataset.path
			const index = dataset.index
			//如果是特殊跳转界面
			if (this.data.list[index].isSpecial) {
				wx.navigateTo({
					url: path
				})
			} else {
				//正常的tabbar切换界面
				wx.switchTab({
					url: path
				})
				this.setData({
					selected: index
				})
			}
		}
	}
});